from datetime import datetime

from application import db


class BaseModel(db.Model):
    # 定义抽象类
    __abstract__ = True
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    create_time = db.Column(db.DateTime, default=datetime.now)


# 轮播图模型
class AdvertiseImage(BaseModel):
    __tablename__ = 'adv_img'
    text = db.Column(db.Text, nullable=False)
    img_url = db.Column(db.String(100), nullable=False)
    # 0:不上线，1：上线
    is_online = db.Column(db.Integer, nullable=False, default=0)
    desc = db.Column(db.Text, nullable=False)
    update_time = db.Column(db.DateTime, default=datetime.now)


# 新闻模型
class News(BaseModel):
    __tablename__ = 'news'
    title = db.Column(db.String(200), nullable=False)
    summary = db.Column(db.Text, nullable=False)
    click = db.Column(db.Integer, nullable=False, default=0)
    img_url = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    # 浏览量
    view = db.Column(db.Integer, default=0)
    # 收藏量
    fav = db.Column(db.Integer, default=0)
    # 点赞量
    like = db.Column(db.Integer, default=0)
    update_time = db.Column(db.DateTime, default=datetime.now)


# 图文分享 顶部菜单栏
class Category(BaseModel):
    __tablename__ = 'category'
    name = db.Column(db.String(50), nullable=False)
    update_time = db.Column(db.DateTime, default=datetime.now)


# 图文分享  一般数据表不会这么字段的，要拆 而且有些字段没有用到
class Share(BaseModel):
    __tablename__ = 'share'
    channel_id = db.Column(db.Integer)
    category_id = db.Column(db.Integer)
    title = db.Column(db.String(50), nullable=False)
    call_index = db.Column(db.String(200), nullable=False)
    link_url = db.Column(db.String(200), nullable=False)
    img_url = db.Column(db.String(100), nullable=False)
    seo_title = db.Column(db.String(100), nullable=False)
    seo_keywords = db.Column(db.String(100), nullable=False)
    seo_description = db.Column(db.Text, nullable=False)
    tags = db.Column(db.String(100), nullable=False)
    summary = db.Column(db.Text, nullable=False)
    content = db.Column(db.Text, nullable=False)
    sort_id = db.Column(db.Integer, default=0)
    click = db.Column(db.Integer, nullable=False, default=0)
    view = db.Column(db.Integer, default=0)
    fav = db.Column(db.Integer, default=0)
    like = db.Column(db.Integer, default=0)
    status = db.Column(db.Integer, default=0)
    is_img = db.Column(db.Integer, default=0)
    is_top = db.Column(db.Integer, default=0)
    is_red = db.Column(db.Integer, default=0)
    is_hot = db.Column(db.Integer, default=0)
    is_slide = db.Column(db.Integer, default=0)
    is_sys = db.Column(db.Integer, default=0)
    user_name = db.Column(db.String(100))
    update_time = db.Column(db.DateTime, default=datetime.now)


# 图文分享缩略图
class ImgThum(BaseModel):
    __tablename__ = 'img_thum'
    # 对应图文数据编号
    pid = db.Column(db.Integer, default=1)
    src = db.Column(db.String(200))


# 后台管理系统 菜单模型
class Menu(BaseModel):
    __tablename__ = 'menu'
    name = db.Column(db.String(50), nullable=False)
    route = db.Column(db.String(100), nullable=False)
    desc = db.Column(db.String(200), nullable=False)
    # 默认为0，即跟菜单
    parent_id = db.Column(db.Integer, nullable=False, default=0)
    menu_level = db.Column(db.Integer, nullable=False, default=0)
    update_time = db.Column(db.DateTime, default=datetime.now)
